import { locations } from "../../../../gpu/locations";
export const Normal_def = /*wgsl*/ `
    fn cal_normal(input: Input)->vec3<f32>{
      var n:vec3<f32>=vec3(0,0,1);
      #if ~{def.normal}
        n=normalize(input.normal);
      #else
        n=normalize(cross(dpdx(input.fragPosition),dpdy(input.fragPosition)));
      #endif 
      return n;
    }
    fn cal_TBN(input: Input, ng:vec3<f32>, normalUv:vec2<f32>)-> mat3x3<f32>{
      var TBN:mat3x3<f32>;
      var t:vec3<f32>;
      var b:vec3<f32>;
      #if ~{def.tangent}
        t = normalize(input.tangent);
        b = normalize(input.bitangent);
      #endif 
      #if ~{def.normalMap}
        var uv_dx:vec3<f32> = dpdx(vec3<f32>(normalUv, 0.0));
        var uv_dy:vec3<f32> = dpdy(vec3<f32>(normalUv, 0.0));
        var t_:vec3<f32> = (uv_dy.y * dpdx(input.fragPosition) - uv_dx.y * dpdy(input.fragPosition)) /(uv_dx.x * uv_dy.y - uv_dy.x * uv_dx.y);
        t = normalize(t_ - ng * dot(ng, t_));
        b = cross(ng, t);
      #endif 
      TBN=mat3x3<f32>(t, b, ng);
      return TBN;
    }
    var<private> normal:vec3<f32>;
  `